using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Diagnostics;
using System;

namespace AzureVMDashboard.UI
{
    public class MainViewModel : ViewModelBase
    {
        #region Properties

        private InfoMessage _statusMessage;
        public InfoMessage StatusMessage
        {
            get { return _statusMessage; }
            set
            {
                if (value != _statusMessage)
                {
                    _statusMessage = value;
                    RaisePropertyChanged("StatusMessage");
                }
            }
        }

        #endregion

        public MainViewModel()
        {
            Logger.LogUpdated += (s,message) => { StatusMessage = message; };
        }

        public void StartAll()
        {
            App.Resources.CurrentSubscription.StartAll();
        }

        public void StopAll()
        {
            App.Resources.CurrentSubscription.StopAll();
        }

        public void RefreshAll()
        {
            App.Resources.CurrentSubscription.RetrieveVMs();
        }

        #region Commands

        private RelayCommand _CmdAbout;
        public RelayCommand CmdAbout
        {
            get
            {
                if (_CmdAbout == null)
                {
                    _CmdAbout = new RelayCommand(() => new AboutView().ShowDialog(), () => true);
                }
                return _CmdAbout;
            }
        }


        private RelayCommand _CmdSettings;
        public RelayCommand CmdSettings
        {
            get
            {
                if (_CmdSettings == null)
                {
                    _CmdSettings = new RelayCommand(() => new SettingsView().ShowDialog(), () => true);
                }
                return _CmdSettings;
            }
        }


        private RelayCommand _CmdOpenLog;
        public RelayCommand CmdOpenLog
        {
            get
            {
                if (_CmdOpenLog == null)
                {
                    _CmdOpenLog = new RelayCommand(() => Process.Start(App.Resources.LogFileName.FullName), () => true);
                }
                return _CmdOpenLog;
            }
        }


        private RelayCommand _CmdRefresh;
        public RelayCommand CmdRefresh
        {
            get
            {
                if (_CmdRefresh == null)
                {
                    _CmdRefresh = new RelayCommand(() => RefreshAll(), () => true);
                }
                return _CmdRefresh;
            }
        }

        private RelayCommand _CmdStart;
        public RelayCommand CmdStart
        {
            get
            {
                if (_CmdStart == null)
                {
                    _CmdStart = new RelayCommand(() => StartAll(), () => true);
                }
                return _CmdStart;
            }
        }

        private RelayCommand _CmdStop;
        public RelayCommand CmdStop
        {
            get
            {
                if (_CmdStop == null)
                {
                    _CmdStop = new RelayCommand(() => StopAll(), () => true);
                }
                return _CmdStop;
            }
        }
        #endregion 
    }
}